<script type="text/javascript">

function LoadTP(str)
{
xmlhttp=GetXmlHttpObject();
if (xmlhttp == null)
{
alert ("Browser does not support HTTP Request");
return;
}

var url = "modules/customers/load_thanhpho.php";
url = url + "?sltinhthanh=" + str;

xmlhttp.onreadystatechange = stateChanged1;
xmlhttp.open("GET", url, true);
xmlhttp.send(null);
}

function stateChanged1()
{
if (xmlhttp.readyState == 4)
{
document.getElementById("tinhthanh").innerHTML = xmlhttp.responseText;

}
}

function GetXmlHttpObject()
{
if (window.XMLHttpRequest)
{
// code for IE7+, Firefox, Chrome, Opera, Safari
return new XMLHttpRequest();
}
if (window.ActiveXObject)
{
// code for IE6, IE5
return new ActiveXObject("Microsoft.XMLHTTP");
}
return null;
}

</script>   
<table class="box-vang5" cellpadding="0" cellspacing="0" width="100%">
        <tbody><tr class="light">
          <td class="text-top">.:. Danh sách hợp đồng</td>
        </tr>
      </tbody></table>
      <table class="box-vang5" cellpadding="0" cellspacing="0" width="100%">
        <tbody><tr class="light"> 
          <td class="t-l"></td>
          <td class="t-c"></td>
          <td class="t-r"></td>
        </tr>
        <tr class="light">
          <td class="c-l"></td>
          <td class="c-c" valign="top">
  <form action="" method="post">

     <p>
    &nbsp;&nbsp;
    <span>Tên hợp đồng</span> 
    <span> 
    	<input type="text" style="width:150px;" name="name" value="<?php echo $_POST['name'];?>"/>
    </span> 
    &nbsp;
    <span>Người quản lý </span>
    <span> 
    	<select name="nguoiql"> 
        	
        	<option value="">--Lựa chọn--</option>
           <?php 
		   		$sql_nql=mysql_query("select account_id,account_name from tb_account_admin");
				while($row_nql=mysql_fetch_array($sql_nql))
				{	
		   ?>
           	<option value="<?php echo $row_nql['account_id'];?>" <?php if($row_nql['account_id']==$_POST['nguoiql']){?> selected="selected"<?php }?>><?php echo $row_nql['account_name'];?> </option>
           <?php }?>
        </select>
    </span>
    &nbsp;Trạng thái<span> 
    	<select id="tthd_txt"  name="trangthai">
            <option value="">Lựa chọn </option>
            <option value="1" <?php if($_POST['trangthai']==1){?> selected="selected"<?php }?>>Đang thực hiện</option>
            <option value="2" <?php if($_POST['trangthai']==2){?> selected="selected"<?php }?>>Kết thúc</option>
            <option value="3" <?php if($_POST['trangthai']==3){?> selected="selected"<?php }?>>Đang hoãn</option>
            <option value="4" <?php if($_POST['trangthai']==4){?> selected="selected"<?php }?>>Hủy</option>
        </select>
    </span>
    <!--
    <span>&nbsp;Ngày ký &nbsp; | Từ ngày 
    	<input type="text" name="start_time" id="start_time" value=""/> 
        &nbsp;Đến ngày
        <input type="text" name="end_time" id="end_time" value=""/> 
    </span>
    &nbsp;
  <script>
	var cal = Calendar.setup({
	  onSelect: function(cal) { cal.hide() },
	  weekNumbers: true
  });
	
	cal.manageFields("start_time", "start_time", "%d/%m/%Y");
	cal.manageFields("end_time", "end_time", "%d/%m/%Y");
		
	</script>
   -->
    <span><input name="button" type="submit" value="Tìm kiếm" class="cs-title-timkiem"/></span>
    &nbsp;&nbsp;</p>
    
 </form>
    <div class="clear" style="height:10px"></div>
<?php 
	$search=$_POST['name'];
	$nguoiql=$_POST['nguoiql'];
	$trangthai=$_POST['trangthai'];
	
?>

<?php 
	$user=$_SESSION['userid'];
	$sqlstring="select  
						contract.id,
						contract.code,
						contract.name,
						contract.kh_id,
						contract.giatri_hd,
						contract.chua_tt,
						contract.ngayky,
						contract.manager,
						contract.creater,
						contract.trangthai_id
					from 
						contract 
					where (contract.creater='$user' or contract.manager='$user')
					";
	if($search!=="" and $nguoiql=="" and $trangthai=="")
		{
			$sqlstring.= "and contract.name like '%$search%'";
		}
	if($search!="" and $nguoiql!="" and $trangthai=="")
		{
			$sqlstring.= "and (contract.name like '%$search%' and contract.manager='$nguoiql')";
		}
	if($search!="" and $nguoiql!="" and $trangthai!="")
		{
			$sqlstring.= "and (contract.name like '%$search%' and contract.manager='$nguoiql' and trangthai_id='$trangthai')";
		}
	if($search=="" and $nguoiql!="" and $trangthai!="")
		{
			$sqlstring.= "and (contract.manager='$nguoiql' and contract.trangthai_id='$trangthai')";
		}
	if($search=="" and $nguoiql=="" and $trangthai!="")
		{
			$sqlstring.= "and contract.trangthai_id='$trangthai'";
		}
	if($search=="" and $nguoiql!="" and $trangthai=="")
		{
			$sqlstring.= "and contract.manager='$nguoiql'";
		}
	$qr1=mysql_query($sqlstring); 
	
  ?>
<table id="box-quick" class="box-quick" border="0" cellpadding="5" cellspacing="0" width="100%">
          <tbody><tr id="title">
           
            <td width="15%">Tên hợp đồng</td>
             <td width="10%">Khách hàng</td>
            <td width="10%">Giá trị</td>
            <td width="10%">Chưa thanh toán</td>
            <td width="10%">Ngày ký</td>
            <td width="10%">Người quản lý</td>
            <td width="10%">Trạng thái</td>
            <td width="7%">Thao tác</td>
          </tr>
         <?php 
		 	while($row=mysql_fetch_array($qr1)) 
			{
				
		 ?>
           <tr class="light" id="value" style="cursor:pointer;" onmouseover="mouse_den(this)" onmouseout="mouse_di(this)" bgcolor="">
            
            <td  class="tdbg_2" style="border-left:1px solid #ccc"><div align="left">&nbsp;<span title="">
				<a href="index.php?tn=contract&hd=contract_detail&id=<?php echo $row['id'];?>"><?php echo $row['name'];?></a>
                 </span>
                </div>
            </td>
           <td align="center">
           	<?php $sql_kh=mysql_query("select id,name_kh,name_com from customers where id='".$row['kh_id']."'");
				$row_kh=mysql_fetch_array($sql_kh);
			 	echo $row_kh['name_com']; echo $row_kh['name_kh'];
			?>
           </td>
             <td><div align="center">&nbsp;<?php  echo $row['giatri_hd'];?></div></td>
            <td align="center">
            	<?php echo $row['chua_tt'];?>
            </td>
            <td align="center"> <?php echo $row['ngayky'];?> </td>
             <td align="center"><?php 
						$sql_ql=mysql_query("select account_id,account_name from tb_account_admin where account_id='".$row['manager']."'");
						while($rs_ql=mysql_fetch_array($sql_ql))
						{
							echo $rs_ql['account_name'];
						}
					?></td>
           <td align="center"> 
           	<?php 
				if($row['trangthai_id']==1){echo 'Đang thực hiện';}
				if($row['trangthai_id']==2){echo 'Kết thúc';}
				if($row['trangthai_id']==3){echo 'Đang hoãn';}
				if($row['trangthai_id']==4){echo 'hủy';}
			?>
           </td>
             <td align="center">          	
				<a onclick="window.location='index.php?tn=contract&hd=contract_edit&id=<?php echo $row['id'];?>';"><img width="16" align="absmiddle" src="../skins/images/edit.png"></a>
													
				<a onclick="if(confirm('Bạn muốn xóa hợp đồng này không?')){window.location='index.php?tn=contract&hd=contract_del&id=<?php echo $row['id'];?>';}"><img width="16" align="absmiddle" src="../skins/images/del.png"></a>
													
                &nbsp;
                            
             </td>
          </tr>
       
         <?php }?>
         
          
        </tbody>
	</table>


      
        </td>
      
      
 <td class="c-r"></td>
        </tr>
        <tr class="light">
          <td class="b-l"></td>
          <td class="b-c"></td>
          <td class="b-r"></td>
        </tr>
      </tbody></table>